﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects.BO_GetObjects;
using System.IO;
using DigiLib;

public partial class Administrator_Controls_Config : Admin_Controls_Base {
    protected void Page_Load(object sender, EventArgs e) {
        base.removeHGC(divMessage);
        if (!IsPostBack) {
            loadData();
        }
    }
    protected void loadData() {
        DataRow ObjR = BO_portal_config.SelectTop(1, 1).Rows[0];
        txtAutoF5.Text = ObjR["AUTO_F5_SECONDS"].ToString();
        txtDomain.Text = ObjR["DOMAIN_NAME"].ToString();
        txtFullname.Text = ObjR["FULL_NAME"].ToString();
        txtMetaContent.Text = ObjR["META_CONTENT_TYPE"].ToString();
        txtMetaDescriontion.Text = ObjR["META_DESCRIPTION"].ToString();
        txtMetaKey.Text = ObjR["META_KEYWORDS"].ToString();
        txtTitle.Text = ObjR["PAGE_TITLE"].ToString();
        cboAutoF5.Checked = Convert.ToBoolean(ObjR["PAGE_AUTO_F5"]);
        ctIcon.Src = "/images/favicon.ico";
    }
    protected void btnSubmit_Click(object sender, EventArgs e) {
        try {

            string autof5 = txtAutoF5.Text.Trim();
            string domain = txtDomain.Text.Trim();
            string fullname = txtFullname.Text.Trim();
            string metacontent = txtMetaContent.Text.Trim();
            string metadesctiption = txtMetaDescriontion.Text.Trim();
            string metakey = txtMetaKey.Text.Trim();
            string title = txtTitle.Text.Trim();
            bool autorefrest = cboAutoF5.Checked;
            try {
                if (fulFavicon.HasFile) {
                    fulFavicon.SaveAs(Server.MapPath("~/images/favicon.ico"));
                }
            } catch (Exception) {
                throw;
            }
            string strResult = BO_portal_config.Update(3, fullname, domain, string.Empty, metakey, metadesctiption, metacontent, title, autorefrest, Convert.ToInt32(autof5), 1, 1, false, string.Empty, true, 3,
             DateTime.Now, Administrator.USER_NAME,
                DateTime.Now,
                Administrator.USER_NAME,
                true);
            if (strResult != "0")
                divMessage.InnerHtml = MessageBox.Success("Hệ Thống", "Cập nhật thành công!");
            else
                divMessage.InnerHtml = MessageBox.Error("Hệ Thống", "Có lỗi trong quá trình xử lý, thử lại sau!");
        } catch (Exception ex) {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát hiện lỗi xảy ra !<br />" + ex.Message);
        }
    }
}
